//
//  LQL_photoMainViewController.m
//  Drops
//
//  Created by dllo on 16/5/23.
//  Copyright © 2016年 Drops.er. All rights reserved.
//

#import "LQL_photoMainViewController.h"
#import "LQL_filterViewController.h"
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
@interface LQL_photoMainViewController ()
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIView *menuView;
@property (nonatomic, retain) UIButton *filterButton;
@property (nonatomic, retain) UIButton *editorButton;
@end

@implementation LQL_photoMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBar.translucent = YES;
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT / 10 * 9)];
    self.imageView.backgroundColor = [UIColor whiteColor];
    
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.imageView.image = _picture;
    [self.view addSubview:_imageView];
    
    self.imageView.userInteractionEnabled = YES;
    
    UIButton *saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    saveButton.frame = CGRectMake(0, 0, 40, 30);
    [saveButton setImage:[UIImage imageNamed:@"save.png"] forState:0];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:saveButton];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 0, 40, 30);
    [backButton setImage:[UIImage imageNamed:@"back.png"] forState:0];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    [backButton addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.imageView addGestureRecognizer:tap];
    
    self.menuView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENHEIGHT / 10 * 9, SCREENWIDTH, SCREENHEIGHT / 10)];
    self.menuView.backgroundColor = [UIColor colorWithRed:236 / 255.0 green:73 / 255.0 blue:63 / 255.0 alpha:0.8];
    [self.view addSubview:self.menuView];
    self.menuView.hidden = YES;
    
//    创建滤镜和编辑两个button
    self.filterButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.filterButton.frame = CGRectMake(SCREENWIDTH / 8, self.menuView.frame.size.height / 4, SCREENWIDTH / 4, self.menuView.frame.size.height / 2);
    [self.menuView addSubview:self.filterButton];
    self.filterButton.backgroundColor = [UIColor purpleColor];
    [self.filterButton setTitle:@"滤镜" forState:UIControlStateNormal];
    [self.filterButton addTarget:self action:@selector(clickFilterButton) forControlEvents:UIControlEventTouchUpInside];
    
    self.editorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.editorButton.frame = CGRectMake(SCREENWIDTH / 8 * 5, self.menuView.frame.size.height / 4, SCREENWIDTH / 4, self.menuView.frame.size.height / 2);
    [self.menuView addSubview:self.editorButton];
    self.editorButton.backgroundColor = [UIColor purpleColor];
    [self.editorButton setTitle:@"调整" forState:UIControlStateNormal];
    [self.editorButton addTarget:self action:@selector(clickEditorButton) forControlEvents:UIControlEventTouchUpInside];
}
- (void)clickFilterButton{
    LQL_filterViewController *filterVC = [[LQL_filterViewController alloc] init];
    [self.navigationController pushViewController:filterVC animated:YES];
    filterVC.originImage = self.picture;
}
- (void)clickEditorButton{
    
}




- (void)tapAction:(UITapGestureRecognizer *)tap {
    NSLog(@"counttttttt:%ld", self.count);
    self.count+=1;
    NSInteger times_count = self.count % 2;
    if (times_count == 0) {
        
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        self.menuView.hidden = YES;
    } else {
        
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        self.menuView.hidden = NO;
    }
}

- (void)backAction:(UIButton *)button {
    UIImagePickerController *imagePicker = (UIImagePickerController *)self.navigationController;
    
    if (self.flag == NO) {
        
        [imagePicker dismissViewControllerAnimated:YES completion:nil];
        
    } else {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
